package ebiz.buddhist.texts;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Spinner;



public class kor_JijangView extends Activity {
	ArrayAdapter<String> adspin;
	ArrayList<String> mList;
	
	int mValue;
	String compareStr;
	String mpPathStr; 
	String RenameStr;  
	String strMenuname="지장경";
	int menuNum;
	public String[] intentEx = {"jijang01.mp3","jijang02.mp3","jijang03.mp3","jijang04.mp3"
			,"jijang05.mp3","jijang06.mp3","jijang07.mp3","jijang08.mp3","jijang09.mp3",
			"jijang10.mp3","jijang11.mp3","jijang12.mp3","jijang13.mp3"};
	public String[] strUrl = {
			"file:///android_asset/jijang/jijang01.html","file:///android_asset/jijang/jijang02.html","file:///android_asset/jijang/jijang03.html",
			"file:///android_asset/jijang/jijang04.html","file:///android_asset/jijang/jijang05.html","file:///android_asset/jijang/jijang06.html",
			"file:///android_asset/jijang/jijang07.html","file:///android_asset/jijang/jijang08.html","file:///android_asset/jijang/jijang09.html",
			"file:///android_asset/jijang/jijang10.html","file:///android_asset/jijang/jijang11.html","file:///android_asset/jijang/jijang12.html",
			"file:///android_asset/jijang/jijang13.html"};
	public String[] strKorUrl = {
			"file:///android_asset/jijang/kor_jijang01.html","file:///android_asset/jijang/kor_jijang02.html","file:///android_asset/jijang/kor_jijang03.html",
			"file:///android_asset/jijang/kor_jijang04.html","file:///android_asset/jijang/kor_jijang05.html","file:///android_asset/jijang/kor_jijang06.html",
			"file:///android_asset/jijang/kor_jijang07.html","file:///android_asset/jijang/kor_jijang08.html","file:///android_asset/jijang/kor_jijang09.html",
			"file:///android_asset/jijang/kor_jijang10.html","file:///android_asset/jijang/kor_jijang11.html","file:///android_asset/jijang/kor_jijang12.html",
			"file:///android_asset/jijang/kor_jijang13.html"};
	ConnectivityManager cMgr;
	
	boolean mOmitChapter;
	
	String[] arKorJijang = {
			"지장경 목차",
			"제1품 도리천궁에서 신통을 나투다",
			"제2품 분신들이 모이다",
			"제3품 중생의 업연을 살피다",
			"제4품 염부중생이 업보받음",
			"제5품 지옥의 이름",
			"제6품 부처님이 찬탄하시다",
			"제7품 죽은 사람도 산 사람도 이익되다",
			"제8품 염라왕들을 찬탄하시다",
			"제9품 부처님 명호를 부르면",
			"제10품 보시한 공덕을 비교하다",
			"제11품 지신이 법을 옹호하다",
			"제12품 보고 들어 얻는 이익",
			"제13 품 사람과 하늘을 부촉하다"
	};
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.kor_jijang);		
		

	   mList = new ArrayList<String>();
	   compareStr = revIntent();
	   RenameStr = mpReName(compareStr);
	 
	   arKorJijang[0] = "- " + RenameStr + " -";
	  Spinner spin = (Spinner)findViewById(R.id.jijangspinner);
		spin.setPrompt("목차");

			adspin = new ArrayAdapter<String>(this, 
					android.R.layout.simple_spinner_item, arKorJijang);
			adspin.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		  spin.setAdapter(adspin);
	      WebView webview = (WebView) findViewById(R.id.webkit);
	     
	      WebSettings ws = webview.getSettings();

	         ws.setJavaScriptEnabled(true);		// 잡스크립트실행여부
	         ws.setJavaScriptCanOpenWindowsAutomatically(true);
	   ws.setDomStorageEnabled(true);
	      Uri u = getIntent().getData();
	      webview.loadUrl(u.toString());
	            		
		spin.setOnItemSelectedListener(new OnItemSelectedListener() {
			public void onItemSelected(AdapterView<?> parent, View view, 
					int position, long id) {
				mOnSelect(position);
				
			}
			public void onNothingSelected(AdapterView<?> parent) {
			}
		});
	}
	public void CommAct(String exput,int position)
	{
		Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(exput),
                this, kor_JijangView.class);
		intent.putExtra("TextIn",intentEx[position]);
		startActivity(intent);
	}
	public void mOnSelect(int pos)
	{
		switch(pos)
		{
		case 0:
		/*	finish();
			Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("file:///android_asset/jijang01.html"),
	                this, JiJangView.class);
			intent.putExtra("TextIn","jijang01.mp3");
			startActivity(intent);*/
			break;
		case 1:
			finish();
			CommAct(strKorUrl[pos-1],pos-1);
			break;
		case 2:
			finish();
			CommAct(strKorUrl[pos-1],pos-1);
			break;
		case 3:
			finish();
			CommAct(strKorUrl[pos-1],pos-1);
			break;
		case 4:
			finish();
			CommAct(strKorUrl[pos-1],pos-1);
			break;
		case 5:
			finish();
			CommAct(strKorUrl[pos-1],pos-1);
			break;
		case 6:
			finish();
			CommAct(strKorUrl[pos-1],pos-1);
			break;
		case 7:
			finish();
			CommAct(strKorUrl[pos-1],pos-1);
			break;
		case 8:
			finish();
			CommAct(strKorUrl[pos-1],pos-1);
			break;
		case 9:
			finish();
			CommAct(strKorUrl[pos-1],pos-1);
			break;
		case 10:
			finish();
			CommAct(strKorUrl[pos-1],pos-1);
			break;
		case 11:
			finish();
			CommAct(strKorUrl[pos-1],pos-1);
			break;
		case 12:
			finish();
			CommAct(strKorUrl[pos-1],pos-1);
			break;
		case 13:
			finish();
			CommAct(strKorUrl[pos-1],pos-1);
			break;
		case 14:
			finish();
			CommAct(strKorUrl[pos-1],pos-1);
		}
	}
	   	
	   public String mpReName(String str)
	   {
		   String strCompare = str;
		   if(strCompare.compareTo("jijang01.mp3")== 0)
			   strCompare = "제1품 도리천궁에서 신통을 다투다";
		   if(strCompare.compareTo("jijang02.mp3")== 0)
			   strCompare = "제2품 분신들이 모이다";
		   if(strCompare.compareTo("jijang03.mp3")== 0)
			   strCompare = "제3품 중생의 업연을 살피다";
		   if(strCompare.compareTo("jijang04.mp3")== 0)
			   strCompare = "제4품 염부중생이 업보받음";
		   if(strCompare.compareTo("jijang05.mp3")== 0)
			   strCompare = "제5품 지옥의 이름";
		   if(strCompare.compareTo("jijang06.mp3")== 0)
			   strCompare = "제6품 부처님이 찬탄하시다";
		   if(strCompare.compareTo("jijang07.mp3")== 0)
			   strCompare = "제7품 죽은 사람도 산 사람도 이익되다";
		   if(strCompare.compareTo("jijang08.mp3")== 0)
			   strCompare = "제8품 염라왕들을 찬탄하시다";
		   if(strCompare.compareTo("jijang09.mp3")== 0)
			   strCompare = "제9품 부처님 명호를 부르면";
		   if(strCompare.compareTo("jijang10.mp3")== 0)
			   strCompare = "제10품 보시한 공덕을 비교하다";
		   if(strCompare.compareTo("jijang11.mp3")== 0)
			   strCompare = "제11품 지신이 법을 옹호하다";
		   if(strCompare.compareTo("jijang12.mp3")== 0)
			   strCompare = "제12품 보고 들어 얻는 이익";
		   if(strCompare.compareTo("jijang13.mp3")== 0)
			   strCompare = "제13품 사람과 하늘을 부촉하다";
		   return strCompare;
	   }
	   public int SearchUrl()
	   {
		   int i;
		   for(i=0;i < 13;i++)
		   {
			   if(compareStr.compareTo(intentEx[i])==0)
				   break;
		   }
		   return i;
	   }
	   public void onDestroy() {
	       super.onDestroy();
	    
	   }
	  
	   public String revIntent()
	   {
		   Intent intent = getIntent();
		   String text = intent.getStringExtra("TextIn");
		   return text;
	   }
		public boolean onCreateOptionsMenu(Menu menu) {
			super.onCreateOptionsMenu(menu);
			menu.add(0,1,0,strMenuname);
			return true;
		}
		public boolean onOptionsItemSelected(MenuItem item) {
			switch (item.getItemId()) {
			case 1:			
				finish();
				int i = SearchUrl();
				Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(strUrl[i]),
		                this, JiJangView.class);
				intent.putExtra("TextIn",compareStr);
				startActivity(intent);
				return true;		
			}
			return false;
		}
	   
}
